package cn.sh.yhk;

import org.redisson.api.RBlockingDeque;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * Redis 缓存工具类
 *
 * @Classname Yhk
 * @Description TODO
 * @Version 1.0.0
 * @Date 2024/10/16 13:46
 * @Created by y6522
 */
@Component
public class QueueUtils {


    @Autowired
    RedissonClient redissonClient;

    public void addQueue(String key, Object value) {
        redissonClient.getBlockingQueue(key).add(value);
    }


    public Object getQueue(String key) {
        return redissonClient.getBlockingQueue(key).poll();
    }

    public void addDelayQueue(String key, Object value, long delay) {
        RBlockingDeque queue = redissonClient.getBlockingDeque(key);
        redissonClient.getDelayedQueue(queue).offer(value, delay, TimeUnit.SECONDS);
    }

    public Object getDelayQueue(String key) {
        return redissonClient.getBlockingDeque(key).poll();
    }


}
